package facade;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import entidad.Habitacion;

/**
 * Session Bean implementation class HabitacionFacade
 */
@Stateless
@LocalBean
public class HabitacionFacade implements HabitacionFacadeRemote {
	
	@PersistenceContext(unitName = "sgh001EJB")
    private EntityManager em;
    /**
     * Default constructor. 
     */
    public HabitacionFacade() {
        // TODO Auto-generated constructor stub
    }
    
    @Override
    public List<Habitacion> listar() {
    	Query query = em.createQuery("select h from habitacion h");
    	@SuppressWarnings("unchecked")
    	List<Habitacion> result = query.getResultList();
    	return result;
    }
    
    @Override
    public void save(Habitacion habitacion) {
    	em.persist(habitacion);
    }
    
    @Override
    public void edit(Habitacion habitacion) {
    	em.merge(habitacion);
    }
    
    @Override
    public void remove(Habitacion habitacion) {
    	em.remove(habitacion);
    }
}
